<?php
/**
 * Created by JetBrains PhpStorm.
 * User: redsxz
 * Date: 13-10-3
 * Time: 下午3:33
 * To change this template use File | Settings | File Templates.
 */

namespace Tbf\Bundle\AlipayBundle\Api;



use Tbf\Bundle\AlipayBundle\Model\CreatePaymentRequest;
use Tbf\Bundle\AlipayBundle\Entity\Transaction;

class CreatePartnerTradeByBuyer extends AbstractCreatePayment{
    protected function buildRequestData(CreatePaymentRequest $request)
    {
        //支付宝receive_name字段长度bug
        if (strlen($request->getReceiveName())===1){
            $receive_name = $request->getReceiveName().',';
        }else{
            $receive_name = $request->getReceiveName();
        }
        return array(
            'service'=>'create_partner_trade_by_buyer',
            'partner'=>$this->config->getAppKey(),
            '_input_charset'=>'utf-8',
            'notify_url'=>$this->config->getCptbbNotifyUrl(),
            'return_url'=>$this->config->getCptbbReturnUrl(),
            'out_trade_no'=>$request->getTradeId(),
            'subject'=>$request->getSubject(),
            'payment_type'=>1,
            //'total_fee'=>$request->getMoney(),
            'sign_type'=>'MD5',
            'logistics_type'=>'EXPRESS', //物流类型(需要集成进系统?)
            'logistics_fee'=>'0.00',
            'logistics_payment'=>'BUYER_PAY', //物流支付类型
            'price'=>$request->getMoney(),
            'quantity'=>1,
            'receive_name'=>$this->handleReceiveName($request->getReceiveName()),
            'receive_address'=>$request->getReceiveAddress(),
            'receive_zip'=>$request->getReceiveZip(),
            'receive_phone'=>$request->getReceivePhone(),
            'receive_mobile'=>$request->getReceiveMobile(),
        );
    }
    protected function getCreatePaymentType(){
        return Transaction::TYPE_CREATE_PARTNER_TRADE_BY_BUYER;
    }
}